unit UFrameEdicao;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, Buttons, ExtCtrls, ToolWin, ComCtrls, StdCtrls, DBCtrls, DB,
  Menus, ImgList, StdActns, ActnList;

type
  TFrameEdit = class(TFrame)
    CoolBar: TCoolBar;
    paToolsBrowse: TPanel;
    btIncluir: TSpeedButton;
    btEditar: TSpeedButton;
    btAtualizar: TSpeedButton;
    btExcluir: TSpeedButton;
    btGravar: TSpeedButton;
    btCancelar: TSpeedButton;
    paToolsEdit: TPanel;
    SpeedButton1: TSpeedButton;
    btFerramentas: TSpeedButton;
    btAjuda: TSpeedButton;
    btToolBrowse: TSpeedButton;
    SpeedButton3: TSpeedButton;
    DBNavigator: TDBNavigator;
    DataSource: TDataSource;
    ActionList: TActionList;
    DataSetFirst: TAction;
    DataSetPrior: TAction;
    DataSetNext: TAction;
    DataSetLast: TAction;
    DataSetInsert: TAction;
    DataSetDelete: TAction;
    DataSetEdit: TAction;
    DataSetPost: TAction;
    DataSetCancel: TAction;
    DataSetRefresh: TAction;
    actClearField: TAction;
    actLocate: TAction;
    actHelp: TAction;
    actListRefresh: TAction;
    actForm: TAction;
    actLocateDataset: TAction;
    actCountRecord: TAction;
    actFilter: TAction;
    actOrder: TAction;
    actOrderDesc: TAction;
    actMultiSelect: TAction;
    actMultiDelete: TAction;
    actCopySelect: TAction;
    actExportRTF: TAction;
    actExportPDF: TAction;
    actExportExcel: TAction;
    actExportXML: TAction;
    actExportHTML: TAction;
    actExportTXT: TAction;
    actPrintConfig: TFilePrintSetup;
    actPrint: TAction;
    actPrintTextMode: TAction;
    ImageListAct: TImageList;
    PopupMenu: TPopupMenu;
    mniClearField: TMenuItem;
    mniSep1: TMenuItem;
    mniLocate: TMenuItem;
    mniFilter: TMenuItem;
    mniOrder: TMenuItem;
    mniOrderDec: TMenuItem;
    mniSep2: TMenuItem;
    mniListRefresh: TMenuItem;
    mniForm: TMenuItem;
    mniLocateDataset: TMenuItem;
    mniSep3: TMenuItem;
    mniCountRecord: TMenuItem;
    mniMultiSelect: TMenuItem;
    mniMultiDelete: TMenuItem;
    mniCopySelect: TMenuItem;
    Exportarseleo1: TMenuItem;
    mniExportRTF: TMenuItem;
    mniExportPDF: TMenuItem;
    mniExportExcel: TMenuItem;
    mniExportXML: TMenuItem;
    actExportHTML1: TMenuItem;
    XT1: TMenuItem;
    mniSep4: TMenuItem;
    mniPrintConfig: TMenuItem;
    mniPrint: TMenuItem;
    mniPrintTextMode: TMenuItem;
    DataSetPostContinue: TAction;
    procedure btToolBrowseClick(Sender: TObject);
    procedure DataSourceStateChange(Sender: TObject);
    procedure DataSetInsertExecute(Sender: TObject);
    procedure DataSetEditExecute(Sender: TObject);
    procedure DataSetDeleteExecute(Sender: TObject);
    procedure DataSetPostExecute(Sender: TObject);
    procedure DataSetCancelExecute(Sender: TObject);
    procedure DataSetRefreshExecute(Sender: TObject);
  private
    procedure SwitchMode(EditMode: boolean);
    { Private declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
  end;

implementation

{$R *.dfm}

constructor TFrameEdit.Create(AOwner: TComponent);
begin
  inherited;
  SwitchMode(False);
  Self.Height := paToolsBrowse.Height;
end;

procedure TFrameEdit.btToolBrowseClick(Sender: TObject);
var
  APoint: TPoint;
begin
  APoint := TSpeedButton(Sender).ClientToScreen(Point(0, TSpeedButton(Sender).ClientHeight));
  PopupMenu.Popup(APoint.X, APoint.Y);
end;

procedure TFrameEdit.DataSourceStateChange(Sender: TObject);
begin
  SwitchMode( TDataSource(Sender).State in dsEditModes );
end;

procedure TFrameEdit.SwitchMode(EditMode: boolean);
begin
  if EditMode then
  begin
    paToolsEdit.Enabled   := True;
    paToolsEdit.Visible   := True;
    paToolsBrowse.Enabled := False;
    paToolsBrowse.Visible := False;
	  Self.Height := paToolsBrowse.Height;
  end
  else
  begin
    paToolsBrowse.Enabled := True;
    paToolsBrowse.Visible := True;
    paToolsEdit.Enabled   := False;
    paToolsEdit.Visible   := False;
	  Self.Height := paToolsBrowse.Height;
  end;
  Application.ProcessMessages;
end;

procedure TFrameEdit.DataSetInsertExecute(Sender: TObject);
begin
	SwitchMode(True);
end;

procedure TFrameEdit.DataSetEditExecute(Sender: TObject);
begin
	SwitchMode(True);
end;

procedure TFrameEdit.DataSetDeleteExecute(Sender: TObject);
begin
//
end;

procedure TFrameEdit.DataSetPostExecute(Sender: TObject);
begin
	SwitchMode(False);
end;

procedure TFrameEdit.DataSetCancelExecute(Sender: TObject);
begin
	SwitchMode(False);

end;

procedure TFrameEdit.DataSetRefreshExecute(Sender: TObject);
begin
//
end;

end.
